/* Copyright (C) 2005-2013, Unigine Corp. All rights reserved.
 *
 * File:    fragment_base_shadow_proj.h
 * Desc:    Base fragment shadow proj shader
 * Version: 1.02
 * Author:  Alexander Zapryagaev <frustum@unigine.com>
 *
 * This file is part of the Unigine engine (http://unigine.com/).
 *
 * Your use and or redistribution of this software in source and / or
 * binary form, with or without modification, is subject to: (i) your
 * ongoing acceptance of and compliance with the terms and conditions of
 * the Unigine License Agreement; and (ii) your inclusion of this notice
 * in any version of this software that you use or redistribute.
 * A copy of the Unigine License Agreement is available by contacting
 * Unigine Corp. at http://unigine.com/
 */

#ifndef __FRAGMENT_BASE_SHADOW_PROJ_H__
#define __FRAGMENT_BASE_SHADOW_PROJ_H__

/******************************************************************************\
*
* OpenGL/OpenGLES
*
\******************************************************************************/

#ifdef OPENGL || OPENGLES

/*
 */
#ifdef SHADOW && (OPENGL || HAS_EXT_SHADOW_SAMPLERS)

/*
 */
#define SAMPLER_SHADOW_PROJ \
	uniform sampler2DShadow s_texture_7;

/*
 */
fixed shadowProj(sampler2DShadow s_depth,half4 texcoord) {
	#ifdef OPENGL
		fixed shadow = shadow2DProj(s_depth,texcoord);
	#else
		fixed shadow = shadow2DProjEXT(s_depth,texcoord);
	#endif
	return saturate(shadow + s_light_shadow_iradius.y);
}

/*
 */
#define SHADOW_PROJ(COLOR) COLOR *= shadowProj(s_texture_7,s_texcoord_4);

#else

/*
 */
#define SAMPLER_SHADOW_PROJ \
	uniform sampler2D s_texture_7;

/*
 */
#define SHADOW_PROJ(COLOR) { }

#endif

/******************************************************************************\
*
* Direct3D11/Direct3D119
*
\******************************************************************************/

#elif DIRECT3D11 || DIRECT3D119

/*
 */
#define TEXTURE_SHADOW_PROJ \
	Texture2D s_texture_7 : register(t7);

/*
 */
#ifdef SHADOW && HAS_FEATURE_LEVEL_10_0

/*
 */
half shadowProj(Texture2D s_depth,SamplerComparisonState s_depth_sampler_compare,float4 texcoord) {
	float3 sample_texcoord = texcoord.xyz / texcoord.w;
	half shadow = s_depth.SampleCmpLevelZero(s_depth_sampler_compare,sample_texcoord.xy,sample_texcoord.z);
	return saturate(shadow + s_light_shadow_iradius.y);
}

/*
 */
#define SHADOW_PROJ(COLOR) COLOR *= shadowProj(s_texture_7,s_sampler_compare_7,IN.texcoord_4);

#else

/*
 */
#define SHADOW_PROJ(COLOR) { }

#endif

#endif

#endif /* __FRAGMENT_BASE_SHADOW_PROJ_H__ */
